<script>
import { useRouter } from "vue-router";
import { public_status } from "../store/public_status";
import { useStore } from "../store/index";
export default {
  setup() {
    public_status().display = false;

    // # 配置路由
    let router = useRouter();

    // # 用户数据
    let userId = localStorage.getItem("P4_userId");
    let userData = useStore().userData[userId];

    return {
      router,
      userData,
    };
  },
};
</script>

<template>
  <div class="WalletView">
    <!-- 顶部 -->
    <div class="wallet_top">
      <i class="icon-arrow-left iconfont" @click="router.back()"></i>
      <div class="title">钱包</div>
    </div>
    <!-- 顶部 -->

    <!-- 余额 -->
    <div class="blance">
      <div class="big_blance">
        <div class="small">余额</div>
        <span>￥</span>{{ userData.balance }}
      </div>
      <div class="right">
        <div class="logo">
          <div class="pic icon-saoyisao iconfont"></div>
          <span>付款</span>
        </div>
        <router-link to="/recharge" class="logo">
          <div class="pic">￥</div>
          <span>充值</span>
        </router-link>
      </div>
    </div>
    <!-- 余额 -->

    <!-- 优惠券 -->
    <div class="cheap">
      <div class="title">优惠券</div>
      <ul class="list" v-if="userData">
        <li class="item" v-for="(item, i) in userData.coupon" :key="i">
          <div class="limit">
            <div>
              {{ item.value
              }}<span>{{ item.type == "reduce" ? "元" : "折" }}</span>
            </div>

            <h6>满{{ item.limit }}元可用</h6>
          </div>
          <div class="touse">
            <div>
              <div class="intro">{{ item.title }}</div>
              <div class="limit_time">有效期至 2022-11-30</div>
            </div>
            <router-link to="/category" class="btn">立即使用</router-link>
          </div>
        </li>
      </ul>
      <!-- <ul class="past">
        <li class="item">
          <div class="limit">
            <div>6.6<span>折</span></div>
          </div>
          <div class="touse">
            <div>
              <div class="intro">新人6.6折券</div>
              <div class="limit_time">有效期至 2022-10-30</div>
            </div>
            <div class="btn">
              已过期
              <div class="rule">使用规则</div>
            </div>
          </div>
        </li>
      </ul> -->
    </div>
  </div>
</template>

<style lang="scss" scoped>
.WalletView {
  padding-bottom: 100px;

  // todo 顶部
  .wallet_top {
    margin: 0 15px;
    display: flex;
    justify-content: space-between;

    height: 55px;
    line-height: 55px;
    font-size: 17px;
    color: #282828;
    font-weight: 600;
    align-items: center;

    position: sticky;
    top: 0;
    background: #fff;
    z-index: 100;

    > i {
      width: 35px;
      height: 35px;
      line-height: 35px;
      font-size: 14px;
      background-color: #f2f2f2;
      border-radius: 50%;
      text-align: center;
      text-indent: left;
    }

    .title {
      display: inline-block;
      width: max-content;
      position: absolute;
      left: 0;
      right: 0;
      margin: 0 auto;
    }

    .control {
      background-color: #f2f2f2;
      font-size: 14px;
      line-height: 35px;
      height: 35px;
      padding: 0 13px;
      border-radius: 18px;
    }
  }

  // todo 余额
  .blance {
    margin-top: 10px;
    border-top-left-radius: 12px;
    border-top-right-radius: 12px;
    height: 100px;
    margin: 0 15px;
    background-color: #3fdfb0;
    display: flex;
    align-items: center;
    justify-content: space-between;

    .big_blance {
      margin-left: 20px;
      font-size: 24px;
      font-weight: 700;
      color: #21050e;
      .small {
        font-size: 12px;
        color: rgba(41, 41, 41, 0.5);
      }
      span {
        font-size: 14px;
      }
    }
    .right {
      display: flex;

      .logo {
        margin-right: 33px;

        .pic {
          width: 18px;
          height: 18px;
          line-height: 18px;
          border: 2px solid #44594b;
          border-radius: 8px;
          font-size: 13px;
          text-align: center;

          &.iconfont {
            font-size: 12px;
          }
        }
        span {
          font-size: 12px;
          font-weight: 600;
          color: rgba(41, 41, 41, 0.5);
        }
      }
    }
  }

  // todo 优惠券
  .cheap {
    margin: 0 15px;

    .title {
      height: 70px;
      line-height: 70px;
      font-size: 18px;
      color: #131313;
      font-weight: 600;
    }

    .list {
      .item {
        display: flex;
        height: 100px;
        border-radius: 12px;
        background-color: #f9f9f9;
        overflow: hidden;
        margin-bottom: 20px;
        .limit {
          box-sizing: border-box;
          // padding-top: 25px;
          width: 90px;
          height: 100%;
          background-color: #3fdfb0;
          color: #060007;
          font-size: 24px;
          text-align: center;
          position: relative;
          display: flex;
          flex-direction: column;
          justify-content: center;

          font-weight: 700;
          span {
            font-size: 15px;
            color: rgba(7, 0, 0, 0.7);
            font-weight: 600;
          }
          h6 {
            font-size: 10px;
            color: rgba(41, 41, 41, 0.5);
            font-weight: 600;
          }
          &::before {
            content: "";
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background-color: #fff;
            position: absolute;
            top: 40px;
            left: -7px;
          }
        }
        .touse {
          padding: 0 20px;
          height: 100%;
          display: flex;
          align-items: center;
          width: 63%;
          justify-content: space-between;
          // background-color: rgb(206, 130, 130);
          .intro {
            font-size: 19px;
            color: #0f0f0f;
            font-weight: 600;
          }
          .limit_time {
            font-size: 10px;
            color: #c2c1c6;
          }
          .btn {
            height: 25px;
            line-height: 25px;
            border: 2px solid #71d9b6;
            color: #71d9b6;
            font-size: 11px;
            text-align: center;
            //   padding: 0 10px;
            width: 60px;
            border-radius: 18px;
            position: relative;
            .rule {
              position: absolute;
              bottom: -29px;
              left: 3px;
              font-size: 10px;
              color: #c2c1c6;
              scale: 0.8;
            }
          }
        }
      }
    }

    .past {
      .item {
        display: flex;
        height: 100px;
        border-radius: 12px;
        background-color: #f9f9f9;
        overflow: hidden;
        margin-bottom: 20px;

        .limit {
          box-sizing: border-box;
          // padding-top: 25px;
          width: 90px;
          height: 100%;
          background-color: #ebebeb;
          color: #787878;
          font-size: 24px;
          text-align: center;
          position: relative;
          display: flex;
          flex-direction: column;
          justify-content: center;

          font-weight: 700;
          span {
            font-size: 15px;
            color: rgba(123, 120, 120, 0.7);
            font-weight: 600;
          }
          h6 {
            font-size: 10px;
            color: rgba(41, 41, 41, 0.5);
            font-weight: 600;
          }
          &::before {
            content: "";
            width: 14px;
            height: 14px;
            border-radius: 50%;
            background-color: #fff;
            position: absolute;
            top: 40px;
            left: -7px;
          }
        }

        .touse {
          padding: 0 20px;
          height: 100%;
          display: flex;
          align-items: center;
          width: 63%;
          justify-content: space-between;
          // background-color: rgb(206, 130, 130);
          .intro {
            font-size: 19px;
            color: #717171;
            font-weight: 600;
          }
          .limit_time {
            font-size: 10px;
            color: #c2c1c6;
          }
          .btn {
            height: 25px;
            line-height: 25px;
            border: 2px solid #bbbbbb;
            color: #bbbbbb;
            font-size: 11px;
            text-align: center;
            width: 60px;
            border-radius: 18px;
            position: relative;
            .rule {
              position: absolute;
              bottom: -29px;
              left: 3px;
              font-size: 10px;
              color: #c2c1c6;
              scale: 0.8;
            }
          }
        }
      }
    }
  }
}
</style>